package com.cwj;

import javax.annotation.processing.Messager;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementScanner8;
import javax.tools.Diagnostic;
import java.nio.file.Watchable;

/**
 * @author chenwujie
 * @date 2021-02-19 16:18
 */
public class NameChecker {
    private final Messager messager;
    private NameCheckScanner nameCheckScanner = new NameCheckScanner();

    public NameChecker(ProcessingEnvironment processingEnvironment) {
        this.messager = processingEnvironment.getMessager();
    }

    public void checkNames(Element element){
        nameCheckScanner.scan(element);
    }

    private class NameCheckScanner extends ElementScanner8<Void, Void> {
        @Override
        public Void visitType(TypeElement e, Void unused) {
            scan(e.getTypeParameters(), unused);
            // 检查
            messager.printMessage(Diagnostic.Kind.WARNING, "自定义检查");
            super.visitType(e, unused);
            return null;
        }
    }
}
